//角色编辑
var id;
$(function(){		
	id = ly.getUrlParam("id")||'';
	if(id){
		$(".thisName").html("编辑");	
		$(".getFom").getForm({
			"id":id,
			"ajaxform":true
		},function(d){
			$("#attr1").getSelect({
				type:"radio",
				asName:"attr1",
				list:[
					{value:"0",display:"禁用"},
					{value:"1",display:"启用"}
				],
				default:d.attr1			
			});
			$("#attr2").getSelect({
				type:"radio",
				asName:"attr2",
				list:[
					{value:"2",display:"禁止"},
					{value:"1",display:"允许"}
				],
				default:d.attr2			
			});
		});		
	}else{
		$("#thisName").html("新增");
		$("#attr1").getSelect({
			type:"radio",
			asName:"attr1",
			list:[
				{value:"0",display:"禁用"},
				{value:"1",display:"启用"}
			],
			default:1			
		});
		$("#attr2").getSelect({
				type:"radio",
				asName:"attr2",
				list:[
					{value:"2",display:"禁止"},
					{value:"1",display:"允许"}
				],
				default:1		
			});
	}
	//保存
	$("body").on("click","#save-btn",function(event){
		event.preventDefault();
		 var success =  $('#form1').validate('submitValidate');
		 if(success){
			if(id){//编辑
				$(".getFom").submitForm({
					id:id,
					url:site.apiUrl+"/role/updateRole"
				},"role-list.html"); //成功后跳转的页面,可为空
			}else{//新增
				$(".getFom").submitForm({
					url:site.apiUrl+"/role/insertRole"
				},"role-list.html"); //成功后跳转的页面,可为空
			}
		 }
	});
});
